import type { PatientLoginReq } from '../common';
import { getAction, postAction } from '../controller';

interface HealthCardQrcodeInfo {
  gender: string
  birthday: string
  phone1: string
  idNumber: string
  idType: string
  name: string
}

export interface PatientCardReceiveInfoRespVO {
  patientCode?: string
  /**
   * 患者身份证号
   */
  patientIdCard?: string
  patientName?: string
  treatmentCard?: string
}

export interface LoginPatientInfoRespVO {
  /**
   * 患者地址
   */
  address?: string
  /**
   * 患者年龄
   */
  age?: number
  /**
   * 患者生日
   */
  birthday?: string
  /**
   * 患者身份证号
   */
  idCard?: string
  /**
   * 身份证类型
   */
  idCardType?: number
  /**
   * 患者姓名
   */
  patientName?: string
  /**
   * 患者性别
   */
  sex?: number
}

export const PatientApi = {
  /**
   * 获取患者健康卡二维码信息
   * @param healthCardQrCode 二维码文本
   * @returns 患者健康卡信息
   */
  getHealthCardQrcodeInfo: (healthCardQrCode: string) => {
    return getAction<{ rsp: { card: HealthCardQrcodeInfo } }>('/healthcare/patient/getHealthCardInfo', {
      healthCardQrCode
    }, {
      silentLogin: true
    }).then(res => res.rsp.card);
  },

  /**
   * 通过人脸获取患者信息
   * @param params
   * @returns
   */
  onFaceLogin: (params: PatientLoginReq) => {
    return postAction<LoginPatientInfoRespVO>('/system/patient/auth/faceLogin', params, {
      silentLogin: true,
      hideRejectToast: true
    });
  },

  /**
   * 通过诊疗卡号/医保卡获取患者信息
   * @param params
   * @returns
   */
  onHealthCardLogin: (params: PatientLoginReq) => {
    return postAction<LoginPatientInfoRespVO>('/system/patient/auth/otherCardLogin', params, {
      silentLogin: true
    });
  },

  /**
   * 人脸注册
   * @param params
   * @returns
   */
  onFaceRegister: (params: PatientLoginReq) => {
    return postAction<LoginPatientInfoRespVO>('/system/patient/auth/faceRegister', params, {
      silentLogin: true
    });
  },

  // 就诊卡注册
  onMedicalCardRegister: (params: PatientLoginReq) => {
    return postAction<PatientCardReceiveInfoRespVO>('/system/patient/auth/receivePatientCard', params, {
      silentLogin: true,
      hideRejectToast: true
    });
  }
};
